package com.hospital.register.sms.receiver;

import com.hospital.register.common.rabbit.constant.MqConst;
import com.hospital.register.sms.constants.SmsConstants;
import com.hospital.register.sms.service.SmsService;
import com.hospital.register.vo.order.OrderMessageVo;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 监听mq短信消息
 * 新增订单时，由医院模块转发
 *
 * @author 刘逸晖
 */
@Component
public class SmsReceiver {

    /**
     * 处理短信业务
     */
    @Autowired
    private SmsService smsService;

    /**
     * 记录日志
     */
    private final Logger logger = LoggerFactory.getLogger(SmsReceiver.class);

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.QUEUE_MSM_ITEM, durable = "true"),
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_MSM),
            key = {MqConst.ROUTING_MSM_ITEM}
    ))
    public void send(OrderMessageVo orderMessage, Message message, Channel channel) {
        logger.info("监听到短信消息，消息内容：" + orderMessage);
        smsService.sendShortMessage(SmsConstants.getOrderSubmissionTemplate(), orderMessage.getPatientPhone(), orderMessage);
    }

}
